home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 163_02 / test.c < prev    next >
Text File  |  1991-01-05  |  3KB  |  115 lines

  1. /*******************************************************
  2. *                                                      *
  3. *   Full test case for addition of multi-dimensional   *
  4. *   arrays to Small C V2.0 using the modified          *
  5. *   CUG disk #163, and PC Club of Toronto #152.        *
  6. *   Release 1.01                                       *
  7. *                                 -  Don Lang  1/91    *
  8. *******************************************************/
  9.  
  10. #define LASTROW   1
  11. #define CLOSELAST 2
  12. /*
  13.   Declaration required for c.lib
  14.                 */
  15. extern int printf();
  16. /*
  17.     Test for global declaration of a 2-D array and for
  18.     proper initialization.  This will exercise the modified
  19.     Small C functions, "declglb", "initials", and "addsym."
  20.     Size of 1st dimension is determined by the number of
  21.     initialized elements as per the C language definition.
  22.                               */
  23. char garray[][2] = { 1, 2, 3, 4 };
  24.  
  25. int garray2 [3] [3];
  26.  
  27. /* Test to see that 1-D is unaffected. */
  28.  
  29. char gar1D[] = { 1,2 };
  30.  
  31. /*
  32.    Try an external 2-D array of unknown size.
  33.                           */
  34.     /*   (in file: ext.c)    */
  35.  
  36. extern char ext2_D [] [CLOSELAST + 2];
  37.  
  38. main()
  39. {
  40.     /*
  41.        Declare local 2-D array and thus test the
  42.        function "declloc" for 2-D.
  43.                             */
  44.     int i, k, count, larray[3][4];
  45.     count = 0;
  46.     for (i = 0; i < 3; i++)
  47.            for (k=0; k < 4; k++) {
  48.               ext2_D[i][k] = larray[i][k] = count;
  49.               count++;
  50.            }
  51. /*
  52.        The following strange code has been written to test
  53.    the compiler's ability to correctly generate code for
  54.    multi-dimensional array expressions using both variable
  55.    and constant expressions as array indices.  This, and the
  56.    above nested "for" loop, will test the modifications to
  57.    the Small-C expression analyzer; specifically the
  58.    function "heir14."
  59.                               */
  60.     for (i=0; i<3; i++) {
  61.            printf("\n");
  62.            printf(" %d ", larray[i][0]);
  63.            printf(" %d ", larray[i][LASTROW]);
  64.            printf(" %d ", larray[i][2]);
  65.            printf(" %d ", larray[i][3]);
  66.     }
  67.     printf("\n"); 
  68.     printf("\n");
  69.     for (i=0; i<4; i++) printf(" %d ",
  70.               larray[CLOSELAST-2][i]);
  71.     printf("\n");
  72.     for (i=0; i<4; i++) printf(" %d ",
  73.               larray[CLOSELAST/2][i]);
  74.     printf("\n");
  75. /*
  76.     Try printing initialized global character array and the
  77.     processed external.
  78.                           */
  79.     ga_print(2,2, garray);
  80.     for (i=0; i<3; i+=1) {
  81.         printf("\n");
  82.         for (k=0; k<4; k++) printf(" %d ",
  83.                        ext2_D[i][k]);
  84.     }
  85. /*
  86.    Print out 1-D array to see that it hasn't been changed by
  87.    the modifications for "n" dimensions.
  88.                               */
  89.     printf("\n");
  90.     ga2_print(2, gar1D);
  91. }
  92. /*
  93.     This global print function will test passing of array
  94.     arguments, and thus the modified Small C function
  95.     "doargs."
  96.                               */
  97. ga_print (a,b, array) int a,b; char array[][2];
  98. {
  99.     int i,k;
  100.     printf("\n");
  101.     i=0;
  102.     while (i < a) {
  103.         for(k=0; k<b; k++) printf(" %d ",
  104.                        array[i][k]);
  105.         printf("\n");
  106.         i++;
  107.     }
  108. }
  109. ga2_print (a, array) int a; char array[];
  110. {
  111.     int i;
  112.     printf("\n");
  113.     for (i = 0; i < a; i++) printf(" %d ", array[i]);
  114. }
  115.